package org.t236.feign.user;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.t236.commons.model.AjaxResult;
import org.t236.commons.model.User;

@Component
@Slf4j
public class UserRemoteClientFallbackFactory implements FallbackFactory<UserRemoteClient> {
    @Override
    public UserRemoteClient create(Throwable throwable) {
        log.error("用户微服务回退异常", throwable);
        return new UserRemoteClient() {
            @Override
            public AjaxResult find(Long userId) {
                return AjaxResult.error("用户find(long userId)微服务正忙");
            }

            @Override
            public AjaxResult findAll() {
                return AjaxResult.error("用户findAll微服务正忙");
            }

            @Override
            public AjaxResult add(User user) {
                return AjaxResult.error("用户add微服务正忙");
            }
        };
    }
}
